<template>
  <div class="app-container">
    <u-page title="操作日志">
      <u-filtered>

        <el-form :inline="true" :model="listQuery" class="search-form">
          <el-form-item label="时间范围">
            <u-date-time-picker v-model="searchDate" @change="changeSearchDate" />
          </el-form-item>
          <el-form-item label="操作用户">
            <el-input v-model="listQuery.name" placeholder="操作用户" clearable />
          </el-form-item>
          <el-form-item label="操作类型">
            <el-input v-model="listQuery.msg" placeholder="关键词" clearable />
          </el-form-item>
          <el-form-item label="操作地址">
            <el-input v-model="listQuery.ip" placeholder="关键词" clearable />
          </el-form-item>
          <el-form-item label="操作地点">
            <el-input v-model="listQuery.location" placeholder="操作地点" clearable />
          </el-form-item>
          <el-form-item label="请求参数">
            <el-input v-model="listQuery.param" placeholder="关键词" clearable />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="hdlFilter">搜索</el-button>
          </el-form-item>
        </el-form>

      </u-filtered>

      <u-table
        :data="list"
        :loading="listLoading"
        :options="listOptions"
        :columns="columns"
        :pagination.sync="listQuery"
        :fetch="hdlList"
      >
        <template v-slot:right>
          <el-table-column label="操作" align="center" fixed="right">
            <template slot-scope="{ row }">
              <el-button type="text" @click="hdlEdit(row)">详情</el-button>
            </template>
          </el-table-column>
        </template>
      </u-table>

    </u-page>

    <u-dialog title="日志详情" :show.sync="dialogFormVisible" :footer="false">
      <el-form ref="dialogForm" :model="dataForm" label-width="80px">

        <el-form-item label="操作时间">
          {{ dataForm.createdAt | date }}
        </el-form-item>

        <el-form-item label="操作模块">
          {{ dataForm.tag }}
        </el-form-item>

        <el-form-item label="执行动作">
          {{ dataForm.msg }}
        </el-form-item>

        <el-form-item label="操作信息">
          {{ dataForm.name }} / {{ dataForm.ip }} / {{ dataForm.location }}
        </el-form-item>

        <el-form-item label="请求地址">
          {{ dataForm.method }} {{ dataForm.url }}
        </el-form-item>

        <el-form-item label="请求终端">
          {{ dataForm.os }} / {{ dataForm.browser }}
        </el-form-item>

        <el-form-item label="请求方法">
          {{ dataForm.src }}
        </el-form-item>

        <el-form-item label="请求参数">
          <el-alert :title="dataForm.param" type="info" :closable="false" />
        </el-form-item>

        <el-form-item label="响应结果">
          <el-alert :title="dataForm.result" type="info" :closable="false" />
        </el-form-item>

        <el-form-item label="请求耗时">
          <el-tag type="success">{{ dataForm.executeTime }} ms</el-tag>
        </el-form-item>

      </el-form>
    </u-dialog>
  </div>
</template>
<script>

export default {
  data: function() {
    return {
      api: this.$u.api.PluginsGuideLog,
      // 表格
      columns: [
        {
          prop: 'name',
          label: '操作用户',
          align: 'left'
        },
        {
          prop: 'msg',
          label: '操作类型',
          align: 'left'
        },
        {
          prop: 'ip',
          label: '操作地址',
          align: 'left'
        },
        {
          prop: 'location',
          label: '操作地点',
          align: 'left'
        },
        {
          prop: 'success',
          label: '状态',
          align: 'left',
          render: (h, params) => {
            let title = '异常'
            let type = 'danger'
            if (params.row.success) {
              title = '正常'
              type = 'success'
            }
            return h('el-tag', { props: { size: 'small', type: type }}, title)
          }
        },
        {
          prop: 'createdAt',
          label: '操作时间',
          timestamp: true,
          align: 'left'
        },
        {
          prop: 'executeTime',
          label: '耗时/毫秒',
          align: 'left',
          render: (h, params) => {
            return h('el-tag', { props: { size: 'small', type: 'success' }}, params.row.executeTime)
          }
        }
      ],

      list: [],
      listLoading: true,
      listOptions: {
        mutiSelect: true, // boolean 是否多选
        stripe: true // boolean 斑马纹
      },
      listQuery: {
        pageNumber: 1,
        pageSize: 20,
        totalCount: 1,
        beginTime: '',
        endTime: '',
        name: '',
        ip: '',
        location: ''
      },
      dialogFormVisible: false,
      dataForm: {}

    }
  },
  created() {
    this.hdlList()
  },
  methods: {
  }
}
</script>

